{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Pixel importances with a parallel forest of trees\n\n\nThis example shows the use of forests of trees to evaluate the importance\nof the pixels in an image classification task (faces). The hotter the pixel,\nthe more important.\n\nThe code below also illustrates how the construction and the computation\nof the predictions can be parallelized within multiple jobs.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "print(__doc__)\n\nfrom time import time\nimport matplotlib.pyplot as plt\n\nfrom sklearn.datasets import fetch_olivetti_faces\nfrom sklearn.ensemble import ExtraTreesClassifier\n\n# Number of cores to use to perform parallel fitting of the forest model\nn_jobs = 1\n\n# Load the faces dataset\ndata = fetch_olivetti_faces()\nX, y = data.data, data.target\n\nmask = y < 5  # Limit to 5 classes\nX = X[mask]\ny = y[mask]\n\n# Build a forest and compute the pixel importances\nprint(\"Fitting ExtraTreesClassifier on faces data with %d cores...\" % n_jobs)\nt0 = time()\nforest = ExtraTreesClassifier(n_estimators=1000,\n                              max_features=128,\n                              n_jobs=n_jobs,\n                              random_state=0)\n\nforest.fit(X, y)\nprint(\"done in %0.3fs\" % (time() - t0))\nimportances = forest.feature_importances_\nimportances = importances.reshape(data.images[0].shape)\n\n# Plot pixel importances\nplt.matshow(importances, cmap=plt.cm.hot)\nplt.title(\"Pixel importances with forests of trees\")\nplt.show()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.6.9"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}